From 242f8c428b7566ccdc6ff9734086e5f5b8d250c0 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 29 Apr 2015 18:42:52 -0700 Subject: [PATCH] Fix transitively updating dependencies Currently when a dependency is transitively updated the source may not itself be updated, so an update may not happen at all. This commit modifies this behavior to be sure to add the non-updated source to the registry for any matching package which will trigger the source to update itself. --- src/cargo/ops/cargo_generate_lockfile.rs | 6 +++- tests/test_cargo_registry.rs | 38 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index a314003b8..2c97a3dd3 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -73,7 +73,11 @@ pub fn update_lockfile(manifest_path: &Path, .with_precise(Some(precise)); try!(registry.add_sources(&[precise])); } - None => {} + None => { + let imprecise = dep.source_id().clone() + .with_precise(None); + try!(registry.add_sources(&[imprecise])); + } } } } diff --git a/tests/test_cargo_registry.rs b/tests/test_cargo_registry.rs index 3f7a70ebf..4dc750a99 100644 --- a/tests/test_cargo_registry.rs +++ b/tests/test_cargo_registry.rs @@ -733,3 +733,41 @@ test!(fetch_downloads { {downloading} a v0.1.0 (registry [..]) ", updating = UPDATING, downloading = DOWNLOADING))); }); + +test!(update_transitive_dependency { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.5.0" + authors = [] + + [dependencies] + a = "0.1.0" + "#) + .file("src/main.rs", "fn main() {}"); + p.build(); + + r::mock_pkg("a", "0.1.0", &[("b", "*", "normal")]); + r::mock_pkg("b", "0.1.0", &[]); + + assert_that(p.cargo("fetch"), + execs().with_status(0)); + + r::mock_pkg("b", "0.1.1", &[]); + + assert_that(p.cargo("update").arg("-pb"), + execs().with_status(0) + .with_stdout(format!("\ +{updating} registry `[..]` +", updating = UPDATING))); + + assert_that(p.cargo("build"), + execs().with_status(0) + .with_stdout(format!("\ +{downloading} b v0.1.1 (registry file://[..]) +{compiling} b v0.1.1 (registry [..]) +{compiling} a v0.1.0 (registry [..]) +{compiling} foo v0.5.0 ([..]) +", downloading = DOWNLOADING, compiling = COMPILING))); +}); -- 2.30.2